package ee.ttu.rakarh.commands;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import ee.ttu.rakarh.model.data.dao.ItemDAO;
import ee.ttu.rakarh.model.data.dao.ItemDAOImpl;
import ee.ttu.rakarh.model.data.entities.Item;

public class GetUpdateItemForm implements Command {
	public static final Logger LOG = Logger.getLogger(GetUpdateItemForm.class);
	@Override
	public Boolean execute(HttpServletRequest request,
			HttpServletResponse response) {
		
		Item item = new Item();
		ItemDAO itemDAO = new ItemDAOImpl();
		
		try{
			int itemId = Integer.parseInt(request.getParameter("itemId"));
			item = itemDAO.getItemById(itemId);
		}catch (Exception e) {
			LOG.error(e);
		}
		request.setAttribute("item", item);
		return true;
	}

}
